package blancosMikel.model.dao;

import java.sql.SQLException;

import blancosMikel.controller.beans.informativaBeans;

public class informativaDAO extends SigaabmDAO {

	public informativaBeans selectInfo(informativaBeans info) throws Exception {
		StringBuilder query = new StringBuilder();
		try {
			query.append("Select * from informativa");
			conn = this.getConnectionMYSQL();
			ps = conn.prepareStatement(query.toString());
			rs = ps.executeQuery();
			System.out
					.println("dao.informativa.selectInfo.Ejecutado----------> "
							+ query.toString());

			if (rs.next()) {
				info.setNombre(rs.getString(2));
				info.setDireccion(rs.getString(3));
				info.setMail(rs.getString(4));
				info.setBienvenida(rs.getString(5));
				info.setSlogan(rs.getString(6));
				info.setCopy(rs.getString(7));
				System.out
						.println("dao.informativa.selectInfo----------> MoludoInformativoCargado");
			} else {
				throw new Exception(
						"No existe informacion en la BD.Informativa.");
			}

		} catch (SQLException error) {
			throw new Exception(error.getMessage());
		} catch (Exception error) {
			throw new Exception(error.getMessage());
		} finally {
			close(conn);
			close(ps);
			close(rs);
		}
		return info;
	}

	public void updateInformativa(informativaBeans bean) throws Exception {
		try {
			StringBuilder query = new StringBuilder();
			conn = this.getConnectionMYSQL();

			query.append("UPDATE informativa SET ").append("nomb_empresa='")
					.append(bean.getNombre()).append("',direccion='")
					.append(bean.getDireccion()).append("',email='")
					.append(bean.getMail()).append("',bienvenida='")
					.append(bean.getBienvenida()).append("',slogan='")
					.append(bean.getSlogan()).append("',copy='")
					.append(bean.getCopy()).append("'");

			st = conn.createStatement();
			st.executeUpdate(query.toString());
			System.out
					.println("dao.informativaDAO.update.Ejecutado----------> "
							+ query.toString());
			System.out
					.println("dao.informativaDAO.updateModulo----------> actualizado");

		} catch (SQLException error) {
			throw new Exception(error.getMessage());
		} catch (Exception error) {
			throw new Exception(error.getMessage());
		}
		close(conn);
		close(st);
	}
}
